<?php
namespace app\common\model\apiinput;
use think\Model;
use app\common\model\orderdata\Goods;
class Apiyunkefriends extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'api_yunke_friends';
    protected $pk = 'FId';

    public function customerinfo(){
        return $this->hasOne('app\common\model\customer\Customer','CustomerId','CustomerId');
    }
    /**
     * 获取客户的聊天记录
     * @param  [type] $customerId [description]
     * @return [type]             [description]
     */
    public static function get_record($customerId){
        $apfd =  Apiyunkefriends::where('CustomerId',$customerId)->find();
        if(!empty($apfd)){
            //获取关联的业务人员数组
            $data = Apiyunkerecords::where('talker',$apfd['id'])->where('roomid',"")->order(['timestamp desc'])->with('bussinfo')->select();
            foreach ($data as $key => $value) {
                $data[$key]['AddTime'] = date('Y-m-d H:i:s',$value['timestamp']/1000);;
            }
            return $data->toArray();
        }else{
            return [];
        }
    }
}
